﻿using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
namespace BPM.Web.Shared.Data;

/// <summary>
/// 登录菜单-AntDesign菜单类型
/// </summary>
public partial class AntDesignTreeNode : BaseVM, ITreeNode<AntDesignTreeNode, long>
{
    /// <summary>
    /// 主键Id
    /// </summary>
    [DisplayName("业务号")]
    [Required(ErrorMessage = "业务号不能为空")]
    [JsonPropertyName("id")]
    public long Id { get; set; }

    /// <summary>
    /// 父id
    /// </summary>
    [DisplayName("父id")]
    [JsonPropertyName("pid")]
    public long Pid { get; set; }

    /// <summary>
    /// 路由名称, 必须设置,且不能重名
    /// </summary>
    [DisplayName("路由名称, 必须设置,且不能重名")]
    [JsonPropertyName("name")]
    public string? Name { get; set; }

    /// <summary>
    /// 组件
    /// </summary>
    [DisplayName("组件")]
    [JsonPropertyName("component")]
    public string? Component { get; set; }

    /// <summary>
    /// 重定向地址, 访问这个路由时, 自定进行重定向
    /// </summary>
    [DisplayName("重定向地址, 访问这个路由时, 自定进行重定向")]
    [JsonPropertyName("redirect")]
    public string? Redirect { get; set; }

    [JsonPropertyName("meta")]
    public Meta Meta { get; set; } = new();

    /// <summary>
    /// 路径
    /// </summary>
    [DisplayName("路径")]
    [JsonPropertyName("path")]
    public string? Path { get; set; }

    /// <summary>
    /// 控制路由和子路由是否显示在 sidebar
    /// </summary>
    [DisplayName("控制路由和子路由是否显示在 sidebar")]
    [JsonPropertyName("hidden")]
    public bool Hidden { get; set; }

    /// <summary>
    /// 子节点
    /// </summary>
    public IEnumerable<AntDesignTreeNode> Children { get; set; } = Enumerable.Empty<AntDesignTreeNode>();

    public bool HasChildren => Children.Any();

    public long GetId() => Id;

    public long GetPid() => Pid;
}
